<?php
class BaseModel extends spModel {
	/**
	 * @param int $parent_id
	 * @param array $map
	 */
	public function tree($parent_id = 0, $map = array()) {
		$rst = $this->spLinker ()->findAll ( array ('parent_id' => $parent_id ) );
		if (empty ( $map )) {
			return $rst;
		} else {
			return $this->_tree_change_key ( $rst, $map );
		}
	}
	/**
	 *
	 * @param array $arrayList
	 * @param array $map 数组数据与返回数据之间的映射 改变键值
	 */
	protected function _tree_change_key($arrayList, $map = array()) {
		$return_arr = array ();
		foreach ( $arrayList as $List_key => $List_value ) {
			foreach ( $map as $map_key => $map_value ) {
				if (is_string ( $map_key ) && array_key_exists ( $map_key, $List_value )) {
					$return_arr [$List_key] [$map_value] = $List_value [$map_key];
				} else if (is_numeric ( $map_key )) {
					$return_arr [$List_key] [$map_value] = $List_value [$map_value];
				} else {
					return false;
				}
			}
		}
		return $return_arr;
	}
}
?>